<?php
/**
 * Created by PhpStorm.
 * User: 1
 * Date: 2017-02-08
 * Time: 16:16
 */

namespace app\admin\controller;


use app\src\system\logic\CityLogic;
use app\src\system\logic\ProvinceLogic;
use app\src\system\logic\AreaLogic;

class PCA extends Admin
{

    public function index(){
        $type = $this->_param('type',0);
        $code= $this->_param('code',0);
        if("province"==$type) {
            $list = (new CityLogic())->queryNoPaging(array('father' => $code));
            foreach ($list['info'] as $v) {
                $info[] = array_values($v);
            }
            $data['type']="city";
            $data['info']=$info;
            echo json_encode($data);
        }elseif("city"==$type){
            $list = (new AreaLogic())->queryNoPaging(array('father' => $code));
            foreach ($list['info'] as $v) {
                $info[] = array_values($v);
            }
            $data['type']="area";
            $data['info']=$info;
            echo json_encode($data);
        }
    }


    public function pac(){
        $type = $this->_param('type',0);
        $code= $this->_param('code',0);
        if("province"==$type){
            $list = (new ProvinceLogic())->queryNoPaging(array('countryid' => $code));
            foreach ($list['info'] as $v) {
                $info[] = array_values($v);
            }
            $data['type']="province";
            $data['info']=$info;
            echo json_encode($data);
        }elseif("city"==$type) {
            $list = (new CityLogic())->queryNoPaging(array('father' => $code));
            foreach ($list['info'] as $v) {
                $info[] = array_values($v);
            }
            $data['type']="city";
            $data['info']=$info;
            echo json_encode($data);
        }elseif("area"==$type){
            $list = (new AreaLogic())->queryNoPaging(array('father' => $code));
            foreach ($list['info'] as $v) {
                $info[] = array_values($v);
            }
            $data['type']="area";
            $data['info']=$info;
            echo json_encode($data);
        }
    }


}